package outoforder.leetcode;

import org.junit.Test;

/**
 * @author shhjiang_001
 * @create 2020-07-06 23:30
 */

// 最长回文子串
public class Solution516 {
    public int longestPalindromeSubseq(String s) {
        char[] s1 = s.toCharArray();
        int len = s1.length;
        char[] s2 = new char[len];

        for (int i = 0; i < len; i++) {
            s2[len-1-i]=s1[i];
        }
        int[][] dp = new int[len + 1][len + 1];
        for (int i = 1; i <= len; i++) {
            for (int j = 1; j <= len; j++) {
                if (s1[i-1] == s2[j-1]){
                    dp[i][j] = dp[i-1][j-1]+1;
                }else {
                    dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        return dp[len][len];
    }
    @Test
    public void test(){
        System.out.println(longestPalindromeSubseq("bbbab"));
    }
}
